|
|
|
|
|
|
|
1. Draw an ImageList control on your form, and give it a unique name. |
|
|
|
|
|
|
|
|
2. Open the control's Property Pages dialog box by right-clicking the control and selecting Properties. |
|
|
|
|
|
|
|
|
3. Select the Images tab from the Property Pages dialog box (see Figure 12.3). Here you can load graphics files and assign each graphic a unique identifier. |
|
|
|
|
|
|
|
|
4. To add an image, click the Insert Picture button. The Select Picture dialog box then appears. In this dialog box, you can select a bitmap, icon, cursor, GIF, or JPEG file to add to the list. |
|
|
|
|
|
|
|
|
As you add images, they are automatically given indexes (again, see Figure 12.3). You can also give them your own unique string identifiers by typing them in the Key field. Using a key is recommended because it allows you to refer to a specific image by name, no matter what the order of the images. |
|
|
|
|
|
|
|
|
5. When you finish adding images, press OK to close the Property Pages. |
|
|
|
|
|
|
|
|
Figure 12.3
If you set up an ImageList control at designtime, the images are
stored with the form and compiled into the executable program. |
|
|
|
|
|
|
|
|
Setting Up an ImageList with Code |
|
|
|
|
|
|
|
|
You can also set up and change an ImageList at runtime by using program code. When you access an ImageList from code, each image is part of a collection. |
|
|
|
|
|
|
|
|
|
Collections are a fundamental concept used in many areas of Visual Basic besides the ImageList control. If you are new to the topic, keep reading. Collections are discussed throughout the chapter.  |
|
|
|
|
|
|
|
|
|
|
A collection is a group of objects. In the case of the ImageList control, there is a collection called ListImages. The objects stored in this particular collection are the images in the ImageList control. By manipulating the ListImages collection in code, you can add, remove, and change images. For example, the following line of code adds an image to an imagelist called ImageList1: |
|
|
|
|
|
|
|
|
ImageList1.Add ,,LoadPicture("D:\MYDIR\MYPIC.BMP") |
|
|
|
|
|
|
|
|
You can call the Add method of the ListImages collection repeatedly to add multiple images at designtime. Think of a collection as being similar to, but not exactly like, an array. You can |
|
|
|
|
|